﻿using UnityEngine;
using System.Collections;
using ProtoBuf.Message;
using Dict.DataModel;

namespace Room
{
    public class RCAIBaseCamp : RCAIUnionFightBase
    {
        #region 数据
        public InstUFBaseCamp instData;
        public TableUnionFightBaseCamp dictData;
        #endregion

        GameObject die;
        GameObject stand;

        public void PlayStand()
        {
            if (objAni != null)
            {
                objAni.wrapMode = WrapMode.Loop;
                objAni.Play("stand");
                if (die != null && die.activeSelf)
                {
                    die.SetActive(false);
                }

                if (stand != null && !stand.activeSelf)
                {
                    stand.SetActive(true);
                }
            }
        }

        public void PlayDie()
        {
            if (objAni != null)
            {
                objAni.wrapMode = WrapMode.Once;
                objAni.Play("die");

                if (stand != null && stand.activeSelf)
                {
                    stand.SetActive(false);
                }

                if (die != null && !die.activeSelf)
                {
                    die.SetActive(true);
                }
            }
        }

        public RCAIBaseCamp(RoomCharactor owner)
            : base(owner)
        {
            this.type = AIType.UnionBaseCamp;
        }


        public void Init(InstUFBaseCamp instData)
        {
            UpdateData(instData);
            this.camp = instData.camp;
        }

        public void UpdateData(InstUFBaseCamp instData)
        {
            this.instData = instData;
            this.dictData = Dict.Blo.DictUnionFightBaseCampBlo.GetUnionFightBaseCampByID(instData.id+"");
            var url = dictData.CampUrl;
            FindSceneObj(url);

            if (!string.IsNullOrEmpty(dictData.DieEffectUrl) && die==null)
            {
                var dieUrl = url + "/" + dictData.DieEffectUrl;
                die = GameObject.Find(dieUrl);
            }

            if (!string.IsNullOrEmpty(dictData.NormalEffectUrl) && stand == null)
            {
                var standUrl = url + "/" + dictData.NormalEffectUrl;
                stand = GameObject.Find(standUrl);
            }
        }
        
    }
}